namespace vpm 
{
	namespace mina
	{
		namespace detail 
		{
			class AsioUdpConnectorImpl 
			{
				public:
					enum 
					{
						UDP_MAX_RECV_BUF_LEN = 8192
					};

					AsioUdpConnectorImpl(UdpConnectorConfig & config, 
							IoHandler & handler):m_udpConfig(config),
					m_ioHandler(handler),m_udpSocket(m_ioService)
					{
						boost::asio::ip::address::from_string(m_host);
					}

					virtual ~AsioUdpConnectorImpl()
					{
					}

					int connect(int port = 0, const std::string & host = "0.0.0.0");

					void disconnect()
					{
					}

					int process_data(char * pData, int dataLen, 
							int peerPort, const std::string & peerHost)
					{
						return 0; 
					}

					int send_data(MessageContext &msg)
					{
						UdpMessageContext &udpMsg = (UdpMessageContext&) msg; 
						return this->send_data(udpMsg.buffer,udpMsg.length, udpMsg.port,udpMsg.get_host_addr());
					}

					int send_data(const char * pData, size_t dataLen, 
							int port, const std::string & host)
					{
						m_udpSocket.send_to(boost::asio::buffer(pData,dataLen),
								tcp::endpoint(boost::asio::ip::address::from_string(host),port));
						return 0;
					}


					int recv_data(MessageContext & msg)
					{
						udp::endpoint peerPoint; 
						UdpMessageContext &udpMsg = (UdpMessageContext&) msg; 
						udpMsg.length = m_udpSocket.receive_from(boost::asio::buffer(msg.buffer), peerPoint);
						udpMsg.set_host_addr(peerPoint.address().to_string());
						udpMsg.port = peerPoint.port();
						return udpMsg.length;
					}

				private:
					boost::array<char, UDP_MAX_RECV_BUF_LEN >  m_recvBuf; 
					boost::asio::io_service m_ioService; 
					udp::socket m_udpSocket; 
			}
		}

#define UdpConnectorImpl  AsioUdpConnectorImpl 
	}
}
